package com.sx.gongzhong.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.model.PhotoBean;
import com.sx.gongzhong.net.ServiceFactory;

import java.util.List;

/**
 * @desc:
 */
public class PictureAdapter extends BaseQuickAdapter<PhotoBean, BaseViewHolder> {

    Context context;

    List<PhotoBean> datas;

    public PictureAdapter(Context context, @Nullable List<PhotoBean> data) {
        super(R.layout.layout_picture, data);
        this.context = context;
    }

    @Override
    protected void convert(final BaseViewHolder viewHolder, PhotoBean item) {
        String type = item.getFileType();
        ImageView imageView= viewHolder.getView(R.id.iv_picture);
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(R.mipmap.img_fail)
                .error(R.mipmap.img_fail);
        if ("video".equalsIgnoreCase(type)) {
            imageView.setImageResource(R.mipmap.img_video);
        }else if ("audio".equalsIgnoreCase(type)) {
            imageView.setImageResource(R.mipmap.img_audio);
        } else {//图片
            Glide.with(context)
                    .load(ServiceFactory.getUrl(item.getPath()))
                    .apply(options)
                    .into(imageView);
        }
    }
}
